<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="static/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="static/echarts.min.js"></script>
</head>
<body>
<form action="regist" id="form">
    游戏id<input name="gameId">
    日期：<input name="date">
    <input type="button" value="查询柱状图" onclick="getChartData()">
    <input type="button" value="查询饼图" onclick="getPieChartData()">
    <input type="button" value="查询折现图" onclick="getLineChartData()">
</form>
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
    var myChart = echarts.init(document.getElementById('main'));
    var hours = new Array();
    var datas = new Array();
    for (var i = 0; i < 24; i++) {
        hours.push(i);
        datas.push(0);
    }
function getLineChartData(){
    $.ajax({
        url: "regist",
        data: $("#form").serialize(),
        method: "post",
        success: function (data) {
            for (var i = 0; i < 24; i++) {
                datas[i] = 0;
            }
            for (var i = 0; i < data.length; i++) {
                datas[data[i].hour] = data[i].amount;
            }
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '游戏注册数据'
                },
                tooltip: {},
                legend: {
                    data: ['注册人数']
                },
                xAxis: {
                    type: 'category',
                    data: hours
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    name: '人数',
                    data: datas,
                    type:'line'
                }]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    })
}
    function getPieChartData() {
        $.ajax({
            url: "regist",
            data: $("#form").serialize(),
            method: "post",
            success: function (data) {
                var pieData=new Array();
                for(var i=0;i<data.length;i++){
                    pieData.push({name:data[i].hour,value:data[i].amount});
                }

                var option = {
                    title: {
                        text: '同名数量统计',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
//                    legend: {
//                        type: 'scroll',
//                        orient: 'vertical',
//                        right: 10,
//                        top: 20,
//                        bottom: 20,
//                        data: data.legendData,
//
//                        selected: data.selected
//                    },
                    series: [
                        {
                            name: '人数',
                            type: 'pie',
                            radius: '55%',
                            center: ['40%', '50%'],
                            data: pieData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                }
                myChart.setOption(option);
            }
        })
    }

    function getChartData() {
        $.ajax({
            url: "regist",
            data: $("#form").serialize(),
            method: "post",
            success: function (data) {
                for (var i = 0; i < 24; i++) {
                    datas[i] = 0;
                }
                for (var i = 0; i < data.length; i++) {

                    datas[data[i].hour] = data[i].amount;
                }
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: '游戏注册数据'
                    },
                    tooltip: {},
                    legend: {
                        data: ['注册人数']
                    },
                    xAxis: {
                        data: hours
                    },
                    yAxis: {},
                    series: [{
                        name: '人数',
                        type: 'bar',
                        data: datas
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        })
    }

</script>
</body>
</html>